<?php declare(strict_types=1);

namespace app\library;

class Tree {

    public static function getTree(array $arr,int $pid=0,int $level=0,$parentId='pid',$id='rule_id'):array {
        $list =array();
        foreach ($arr as $k=>$v){
            // operate no choose
            if ($v[$parentId] == $pid){
                // $disabled = $v['is_menu'] == 0 ? true : false;
                // $v['disabled'] = $disabled;
                $v['level']=$level;
                $child=self::getTree($arr,$v[$id],$level+1);
                if(count($child)){
                    $v['leaf'] = false; //是否子节点
                    $v['children'] = $child;
                }else{
                    $v['leaf'] = true;
                }
                $list[] = $v;
            }
        }
        return $list;
    }
}
